<?php
	namespace Common\Logic;
	use Common\Model\UserIntegralLogsModel;
	class UserIntegralLogsLogic extends UserIntegralLogsModel{
		/*
		* Function:		getUserIntegralLogsList
		* Description:	用户积分列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getUserIntegralLogsList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getUserIntegralLogsFilter($filter);
			return $this->where($conditon)->order('id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getUserIntegralLogsFilter
		* Description:	用户积分列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getUserIntegralLogsFilter($filter = ''){
			$conditon = array();
			if(!empty($filter['user_id'])){
				$conditon['user_id'] = $filter['user_id'];
			}
         	if(!empty($filter['type'])){
				$conditon['type'] = $filter['type'];
			}
			if(!empty($filter['username'])){
				$wh = array();
				$wh['username'] = array('like','%'.$filter['username'].'%');
				$sql = D('User')->field('id')->where($wh)->select(false);
				$conditon['user_id'] = array('exp','in('.$sql.')');
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getUserIntegralLogsCount
		* Description:	用户积分列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getUserIntegralLogsCount($filter = ''){
			$conditon = $this->getUserIntegralLogsFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addUserIntegralLogs
		* Description:	增加用户积分
		* @param:		$data array 增加的数组
		*/
		public function addUserIntegralLogs($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getUserIntegralLogsInfo
		* Description:	获取用户积分信息 by row
		* @param:		$id int ID
		*/
		public function getUserIntegralLogsInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateUserIntegralLogs
		* Description:	更新用户积分
		* @param:		$data array 更新的数组
		*/
		public function updateUserIntegralLogs($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteUserIntegralLogs
		* Description:	删除用户积分
		* @param:		$id int ID
		*/
		public function deleteUserIntegralLogs($id){
			return $this->where(array('id'=>$id))->delete();
		}
	}
?>